﻿using HelperUnity;
using IYASAKANPCore;
using LibDll;
using Newtonsoft.Json.Linq;
using System;

namespace IYASAKANet_CDDY
{
    public class NetImplementWrite : IWrite
    {

        // 日志路径.
        private string strLogPath;

        public NetImplementWrite()
        {
            // 加载配置项.
            this.LoadConfig();
        }

        /// <summary>
        /// 加载配置项.
        /// </summary>
        private void LoadConfig()
        {
            string strPath = NetCommon.GetDllPath() + "//config.ini";
            IniFileOperation iniFile = new IniFileOperation(strPath);

            this.strLogPath = iniFile.IniReadValue("Log", "DllLogPath");
        }

        public string WriteObject(string strJKID, string strVin, string strJsonInfo)
        {
            string strResult = string.Empty;
            try
            {
                NetCommon.WriteLog(this.strLogPath, "W[" + strVin + "]输入信息 " + strJsonInfo);

                JObject json = JObject.Parse(strJsonInfo);

                if (strJKID == "19W22")
                {
                    // 得到检测类型. 1为OBD,2为排放
                    string strEquipType = GetJsonValue(json["meta"]["equip"]);
                    if(strEquipType == "1")
                    {
                        // 上传OBD信息.
                        var vRet = UploadOBDInfo(strVin, strJsonInfo);
                        if(vRet.IsSuccess)
                        {
                            NetCommon.WriteLog(this.strLogPath, "W[" + strVin + "]上传OBD信息成功！");
                            strResult = NetCommon.GetCorrectResult();
                        }
                        else
                        {
                            NetCommon.WriteLog(this.strLogPath, "W[" + strVin + "]上传OBD信息失败，失败原因为：" + vRet.Message);
                            strResult = NetCommon.GetFailResult(vRet.Message);
                        }
                    }
                    else if(strEquipType == "2")
                    {
                        // 上传排放信息.
                        var vRet = UploadPQInfo(strVin, strJsonInfo);
                        if(vRet.IsSuccess)
                        {
                            NetCommon.WriteLog(this.strLogPath, "W[" + strVin + "]上传排放信息成功! ");
                            strResult = NetCommon.GetCorrectResult();
                        }
                        else
                        {
                            NetCommon.WriteLog(this.strLogPath, "W[" + strVin + "]上传排放信息失败，失败原因为：" + vRet.Message);
                            strResult = NetCommon.GetFailResult(vRet.Message);
                        }
                    }
                }
                else
                {
                    NetCommon.WriteLog(this.strLogPath, "W[" + strVin + "]接口不存在：" + strJKID);
                    strResult = NetCommon.GetFailResult("接口不存在！");
                }
            }
            catch(Exception ex)
            {
                NetCommon.WriteLog(this.strLogPath, "W[" + strVin + "]上传时出现错误，：" + ex.Message);
                strResult = NetCommon.GetFailResult(ex.Message);
            }

            NetCommon.WriteLog(this.strLogPath, "W[" + strVin + "]上传完成后返回结果 " + strResult);
            return strResult;
        }

        /// <summary>
        /// 上传OBD信息.
        /// </summary>
        /// <param name="strVin"></param>
        /// <param name="strJsonInfo"></param>
        /// <returns></returns>
        private ReturnInfo UploadOBDInfo(string strVin, string strJsonInfo)
        {
            ReturnInfo ret = new ReturnInfo();
            try
            {
                // 上传基本信息.
                var vRet = UploadVehicleData(strVin, strJsonInfo);
                if (vRet.IsSuccess == false)
                {
                    ret.IsSuccess = false;
                    ret.Message = "上传基本信息错误:" + vRet.Message;
                    NetCommon.WriteLog(this.strLogPath, "W[" + strVin + "]上传基本信息错误:" + vRet.Message);
                    return ret;
                }

                NetCommon.WriteLog(this.strLogPath, "W[" + strVin + "]上传基本信息成功！");

                // 上传检测信息.
                vRet = UploadTestData(strVin, strJsonInfo);
                if (vRet.IsSuccess == false)
                {
                    ret.IsSuccess = false;
                    ret.Message = "上传检测信息错误:" + vRet.Message;
                    NetCommon.WriteLog(this.strLogPath, "W[" + strVin + "]上传检测信息错误:" + vRet.Message);
                    return ret;
                }

                NetCommon.WriteLog(this.strLogPath, "W[" + strVin + "]上传检测信息成功！");

                // 上传OBD过程信息.
                vRet = UploadProcessData(strVin, strJsonInfo);
                if (vRet.IsSuccess == false)
                {
                    ret.IsSuccess = false;
                    ret.Message = "上传OBD过程信息错误:" + vRet.Message;
                    NetCommon.WriteLog(this.strLogPath, "W[" + strVin + "]上传OBD过程信息错误: " + vRet.Message);
                    return ret;
                }

                NetCommon.WriteLog(this.strLogPath, "W[" + strVin + "]上传OBD所有信息成功！");
                ret.IsSuccess = true;
            }
            catch (Exception ex)
            {
                ret.IsSuccess = false;
                ret.Message = ex.Message;
                NetCommon.WriteLog(this.strLogPath, "W[" + strVin + "]上传OBD出现错误：" + ex.Message);
            }

            return ret;
        }

        /// <summary>
        /// 上传排放信息.
        /// </summary>
        /// <param name="strVin"></param>
        /// <param name="strJsonInfo"></param>
        /// <returns></returns>
        private ReturnInfo UploadPQInfo(string strVin, string strJsonInfo)
        {
            ReturnInfo ret = new ReturnInfo();
            try
            {
                //上传OBD相关信息.
                var vRetOBD = this.UploadOBDInfo(strVin, strJsonInfo);
                if(vRetOBD.IsSuccess)
                {
                    JObject json = JObject.Parse(strJsonInfo);
                    string testType = GetJsonValue(json["data"]["testData"]["testType"]);

                    //上传双怠速
                    if (testType == "1")
                    {
                        var vRetSDS = this.UploadSDSData(strVin, strJsonInfo);
                        if(vRetSDS.IsSuccess == false)
                        {
                            ret.IsSuccess = vRetSDS.IsSuccess;
                            ret.Message = "上传双怠速失败：" + vRetSDS.Message;
                            NetCommon.WriteLog(this.strLogPath, "W[" + strVin + "]上传双怠速失败：" + vRetSDS.Message);
                        }
                        else
                        {
                            ret.IsSuccess = true;
                            NetCommon.WriteLog(this.strLogPath, "W[" + strVin + "]上传双怠速成功！");
                        }
                    }

                    //Asm
                    if (testType == "2")
                    {
                        var vRetAsm = this.UploadAsmData(strVin, strJsonInfo);
                        if (vRetAsm.IsSuccess == false)
                        {
                            ret.IsSuccess = vRetAsm.IsSuccess;
                            ret.Message = "上传稳态失败：" + vRetAsm.Message;
                            NetCommon.WriteLog(this.strLogPath, "W[" + strVin + "]上传稳态失败：" + vRetAsm.Message);
                        }
                        else
                        {
                            ret.IsSuccess = true;
                            NetCommon.WriteLog(this.strLogPath, "W[" + strVin + "]上传稳态成功！");
                        }
                    }
                    //上传vmas
                    if (testType == "3")
                    {
                        var vRetVmas = this.UploadVmasData(strVin, strJsonInfo);
                        if (vRetVmas.IsSuccess == false)
                        {
                            ret.IsSuccess = vRetVmas.IsSuccess;
                            ret.Message = "上传简易瞬态失败：" + vRetVmas.Message;
                            NetCommon.WriteLog(this.strLogPath, "W[" + strVin + "]上传简易瞬态失败：" + vRetVmas.Message);
                        }
                        else
                        {
                            ret.IsSuccess = true;
                            NetCommon.WriteLog(this.strLogPath, "W[" + strVin + "]上传简易瞬态成功！");
                        }
                    }
                    //上传加载减速
                    if (testType == "4")
                    {
                        var vRetLD = this.UploadLugdownData(strVin, strJsonInfo);
                        if (vRetLD.IsSuccess == false)
                        {
                            ret.IsSuccess = vRetLD.IsSuccess;
                            ret.Message = "上传加载减速失败：" + vRetLD.Message;
                            NetCommon.WriteLog(this.strLogPath, "W[" + strVin + "]上传加载减速失败：" + vRetLD.Message);
                        }
                        else
                        {
                            ret.IsSuccess = true;
                            NetCommon.WriteLog(this.strLogPath, "W[" + strVin + "]上传加载减速成功！");
                        }
                    }
                    //上传自由加速
                    if (testType == "6")
                    {
                        var vRetZYJS = this.UploadZYJSData(strVin, strJsonInfo);
                        if (vRetZYJS.IsSuccess == false)
                        {
                            ret.IsSuccess = vRetZYJS.IsSuccess;
                            ret.Message = "上传自由加速失败：" + vRetZYJS.Message;
                            NetCommon.WriteLog(this.strLogPath, "W[" + strVin + "]上传自由加速失败：" + vRetZYJS.Message);
                        }
                        else
                        {
                            ret.IsSuccess = true;
                            NetCommon.WriteLog(this.strLogPath, "W[" + strVin + "]上传自由加速成功！");
                        }
                    }

                    if(ret.IsSuccess)
                    {
                        // 上传环境参数
                        var vRetPara = this.UploadEnvData(strVin, strJsonInfo);
                        if (vRetPara.IsSuccess)
                        {
                            // 上传检测设备
                            var vRetDev = this.UploadEquipment(strVin, strJsonInfo);

                            if (vRetDev.IsSuccess)
                            {
                                ret.IsSuccess = true;
                                ret.Message = "上传成功！";
                                NetCommon.WriteLog(this.strLogPath, "[" + strVin + "]上传所有排放数据成功！");
                            }
                            else
                            {
                                ret.IsSuccess = false;
                                ret.Message = "上传检测设备失败：" + vRetDev.Message;
                                NetCommon.WriteLog(this.strLogPath, "W[" + strVin + "]上传检测设备失败：" + vRetDev.Message);
                            }
                        }
                        else
                        {
                            ret.IsSuccess = false;
                            ret.Message = "上传环境参数失败：" + vRetPara.Message;
                            NetCommon.WriteLog(this.strLogPath, "W[" + strVin + "]上传环境参数失败：" + vRetPara.Message);
                        }
                    }
                }
                else
                {
                    ret = vRetOBD;
                }
            }
            catch (Exception ex)
            {
                ret.IsSuccess = false;
                ret.Message = ex.Message;
                NetCommon.WriteLog(this.strLogPath, "W[" + strVin + "]上传排放出现错误：" + ex.Message);
            }

            return ret;
        }


        #region Upload functions

        /// <summary>
        /// 上传检测设备.
        /// </summary>
        /// <param name="strVin"></param>
        /// <param name="strJsonInfo"></param>
        /// <returns></returns>
        private ReturnInfo UploadEquipment(string strVin, string strJsonInfo)
        {
            ReturnInfo ret = new ReturnInfo();
            try
            {
                JObject json = JObject.Parse(strJsonInfo);
                string vehicleModel = GetJsonValue(json["vehicleData"]["vehicleModel"]);
                string vin = GetJsonValue(json["vehicleData"]["vin"]);
                string xxgkbh = GetJsonValue(json["vehicleData"]["xxgkbh"]);

                string analyManuf = GetJsonValue(json["data"]["equipmentData"]["analyManuf"]);
                string analyModel = GetJsonValue(json["data"]["equipmentData"]["analyModel"]);
                string analyDate = GetJsonValue(json["data"]["equipmentData"]["analyDate"]);
                string analyName = GetJsonValue(json["data"]["equipmentData"]["analyName"]);
                string dynoModel = GetJsonValue(json["data"]["equipmentData"]["dynoModel"]);
                string dynoManuf = GetJsonValue(json["data"]["equipmentData"]["dynoManuf"]);

                // 上传车辆基本信息.
                string[] strPara = new string[] { vin, vehicleModel, xxgkbh, analyManuf, analyModel, analyDate, analyName, dynoModel, dynoManuf };
                ret = dataOperation.SaveENV_TESTEQUIPMENTInfo(strPara);

                if (ret.IsSuccess == false)
                {
                    ret.Message = "上传设备信息错误:" + ret.Message;
                }
            }
            catch (Exception ex)
            {
                ret.IsSuccess = false;
                ret.Message = ex.Message;
            }

            return ret;
        }

        /// <summary>
        /// 上传基本信息.
        /// </summary>
        /// <param name="strVin"></param>
        /// <param name="strJsonInfo"></param>
        /// <returns></returns>
        private ReturnInfo UploadVehicleData(string strVin, string strJsonInfo)
        {
            ReturnInfo ret = new ReturnInfo();
            try
            {
                JObject json = JObject.Parse(strJsonInfo);
                string vehicleModel = GetJsonValue(json["vehicleData"]["vehicleModel"]);
                string vin = GetJsonValue(json["vehicleData"]["vin"]);
                string xxgkbh = GetJsonValue(json["vehicleData"]["xxgkbh"]);
                string sb = GetJsonValue(json["vehicleData"]["sb"]);
                string sccmc = GetJsonValue(json["vehicleData"]["sccmc"]);
                string sccdz = GetJsonValue(json["vehicleData"]["sccdz"]);
                string fdjh = GetJsonValue(json["vehicleData"]["fdjh"]);
                string fdjsb = GetJsonValue(json["vehicleData"]["fdjsb"]);
                string fdjsccdz = GetJsonValue(json["vehicleData"]["fdjsccdz"]);
                string scdate = GetJsonValue(json["vehicleData"]["scdate"]);

                // 上传车辆基本信息.
                string[] strPara = new string[] { vin, vehicleModel, xxgkbh, sb, sccmc, sccdz, scdate,  fdjh, fdjsb, fdjsccdz };
                ret = dataOperation.SaveENVCarInfo(strPara);

                if(ret.IsSuccess == false)
                {
                    ret.Message = "上传基本信息错误:" + ret.Message;
                }
            }
            catch(Exception ex)
            {
                ret.IsSuccess = false;
                ret.Message = ex.Message;
            }

            return ret;
        }

        /// <summary>
        /// 上传检测数据.
        /// </summary>
        /// <param name="strVin"></param>
        /// <param name="strJsonInfo"></param>
        /// <returns></returns>
        private ReturnInfo UploadTestData(string strVin, string strJsonInfo)
        {
            ReturnInfo ret = new ReturnInfo();
            try
            {
                JObject json = JObject.Parse(strJsonInfo);

                string vehicleModel = GetJsonValue(json["vehicleData"]["vehicleModel"]);
                string vin = GetJsonValue(json["vehicleData"]["vin"]);
                string xxgkbh = GetJsonValue(json["vehicleData"]["xxgkbh"]);
                string testType = GetJsonValue(json["data"]["testData"]["testType"]);
                string testNo = GetJsonValue(json["data"]["testData"]["testNo"]);
                string testDate = GetJsonValue(json["data"]["testData"]["testDate"]);
                string apass = GetJsonValue(json["data"]["testData"]["apass"]);
                string opass = GetJsonValue(json["data"]["testData"]["opass"]);
                string otestdate = GetJsonValue(json["data"]["testData"]["otestdate"]);
                string epass = GetJsonValue(json["data"]["testData"]["epass"]);
                string result = GetJsonValue(json["data"]["testData"]["result"]);

                // 上传检测数据.
                string[] strPara = new string[] { vin, vehicleModel, xxgkbh, testType, testNo,  testDate, apass, opass, otestdate, epass, result };
                ret = dataOperation.SaveENV_TESTINFOInfo(strPara);

                if (ret.IsSuccess == false)
                {
                    ret.Message = "上传检测结果错误:" + ret.Message;
                }
            }
            catch (Exception ex)
            {
                ret.IsSuccess = false;
                ret.Message = ex.Message;
            }

            return ret;
        }

        /// <summary>
        /// 上传检测过程数据.
        /// </summary>
        /// <param name="strVin"></param>
        /// <param name="strJsonInfo"></param>
        /// <returns></returns>
        public ReturnInfo UploadProcessData(string strVin, string strJsonInfo)
        {
            ReturnInfo ret = new ReturnInfo();
            try
            {
                JObject json = JObject.Parse(strJsonInfo);

                string vehicleModel = GetJsonValue(json["vehicleData"]["vehicleModel"]);
                string vin = GetJsonValue(json["vehicleData"]["vin"]);
                string xxgkbh = GetJsonValue(json["vehicleData"]["xxgkbh"]);
                string obd = GetJsonValue(json["data"]["processData"]["obd"]);
                string odo = GetJsonValue(json["data"]["processData"]["odo"]);

                JArray moduleData = JArray.Parse(GetJsonValue(json["data"]["processData"]["moduleData"]));

                string strProcessDataBatch = Guid.NewGuid().ToString();

                for (int i = 0; i < moduleData.Count; i++)
                {
                    JObject jo = JObject.Parse(moduleData[i].ToString());

                    string calID = GetJsonValue(jo["calID"]);
                    string cvn = GetJsonValue(jo["cvn"]);
                    string moduleID = GetJsonValue(jo["moduleID"]);

                    var vRetPro = dataOperation.SaveENV_MODULE(vin, vehicleModel, xxgkbh, moduleID, calID, cvn, strProcessDataBatch);
                    if(vRetPro.IsSuccess)
                    {
                        NetCommon.WriteLog(this.strLogPath, "W[" + strVin + "]上传OBD过程数据表成功！");
                    }
                    else
                    {
                        NetCommon.WriteLog(this.strLogPath, "W[" + strVin + "]上传OBD过程数据表失败！" + vRetPro.Message);
                    }
                }

                // 上传检测过程数据.
                ret = dataOperation.SaveENV_PROCESSDATA(vin, vehicleModel, xxgkbh, obd, odo, strProcessDataBatch);
            }
            catch (Exception ex)
            {
                ret.IsSuccess = false;
                ret.Message = ex.Message;
            }

            return ret;
        }

        /// <summary>
        /// 上传环境参数.
        /// </summary>
        /// <param name="strVin"></param>
        /// <param name="strJsonInfo"></param>
        /// <returns></returns>
        private ReturnInfo UploadEnvData(string strVin, string strJsonInfo)
        {
            ReturnInfo ret = new ReturnInfo();
            try
            {
                JObject json = JObject.Parse(strJsonInfo);

                string vehicleModel = GetJsonValue(json["vehicleData"]["vehicleModel"]);
                string vin = GetJsonValue(json["vehicleData"]["vin"]);
                string xxgkbh = GetJsonValue(json["vehicleData"]["xxgkbh"]);
                string rh = GetJsonValue(json["data"]["envData"]["rh"]);
                string ap = GetJsonValue(json["data"]["envData"]["ap"]);
                string et = GetJsonValue(json["data"]["envData"]["et"]);

                // 上传环境参数.
                string[] strPara = new string[] { vin, vehicleModel, xxgkbh, rh, et,ap  };
                ret = dataOperation.SaveENV_PARAMInfo(strPara);

                if (ret.IsSuccess == false)
                {
                    ret.Message = "上传环境参数错误:" + ret.Message;
                }

            }
            catch (Exception ex)
            {
                ret.IsSuccess = false;
                ret.Message = ex.Message;
            }

            return ret;
        }

        /// <summary>
        /// 简易瞬态
        /// </summary>
        /// <param name="strVin"></param>
        /// <param name="strJ"></param>
        /// <returns></returns>
        private ReturnInfo UploadVmasData(string strVin, string strJsonInfo)
        {
            ReturnInfo ret = new ReturnInfo();
            try
            {
                JObject json = JObject.Parse(strJsonInfo);

                string vehicleModel = GetJsonValue(json["vehicleData"]["vehicleModel"]);
                string vin = GetJsonValue(json["vehicleData"]["vin"]);
                string xxgkbh = GetJsonValue(json["vehicleData"]["xxgkbh"]);
                string vrhc = GetJsonValue(json["data"]["resultData"]["svmassData"]["vrhc"]);
                string vlhc = GetJsonValue(json["data"]["resultData"]["svmassData"]["vlhc"]);
                string vrco = GetJsonValue(json["data"]["resultData"]["svmassData"]["vrco"]);
                string vlco = GetJsonValue(json["data"]["resultData"]["svmassData"]["vlco"]);
                string vrnox = GetJsonValue(json["data"]["resultData"]["svmassData"]["vrnox"]);
                string vlnox = GetJsonValue(json["data"]["resultData"]["svmassData"]["vlnox"]);

                // 上传环境参数.
                string[] strPara = new string[] { vin, vehicleModel, xxgkbh, vrhc, vlhc, vrco, vlco, vrnox, vlnox };
                ret = dataOperation.SaveENV_TRANSIENTInfo(strPara);

                if (ret.IsSuccess == false)
                {
                    ret.Message = "上传简易瞬态错误:" + ret.Message;
                }

            }
            catch (Exception ex)
            {
                ret.IsSuccess = false;
                ret.Message = ex.Message;
            }

            return ret;
        }

        /// <summary>
        /// 自由加速法
        /// </summary>
        /// <param name="strVin"></param>
        /// <param name="strJ"></param>
        /// <returns></returns>
        private ReturnInfo UploadZYJSData(string strVin, string strJsonInfo)
        {
            ReturnInfo ret = new ReturnInfo();
            try
            {
                JObject json = JObject.Parse(strJsonInfo);

                string vehicleModel = GetJsonValue(json["vehicleData"]["vehicleModel"]);
                string vin = GetJsonValue(json["vehicleData"]["vin"]);
                string xxgkbh = GetJsonValue(json["vehicleData"]["xxgkbh"]);
                string rev = GetJsonValue(json["data"]["resultData"]["faData"]["rev"]);
                string rateRev = GetJsonValue(json["data"]["resultData"]["faData"]["rateRev"]);
                string smokeK1 = GetJsonValue(json["data"]["resultData"]["faData"]["smokeK1"]);
                string smokeK2 = GetJsonValue(json["data"]["resultData"]["faData"]["smokeK2"]);
                string smokeK3 = GetJsonValue(json["data"]["resultData"]["faData"]["smokeK3"]);
                string smokeAvg = GetJsonValue(json["data"]["resultData"]["faData"]["smokeAvg"]);
                string smokeKLimit = GetJsonValue(json["data"]["resultData"]["faData"]["smokeKLimit"]);

                // 上传环境参数.
                string[] strPara = new string[] { vin, vehicleModel, xxgkbh, rev, rateRev, smokeK1, smokeK2, smokeK3, smokeAvg, smokeKLimit };
                ret = dataOperation.SaveENV_FREEMETHODInfo(strPara);

                if (ret.IsSuccess == false)
                {
                    ret.Message = "上传自由加速错误:" + ret.Message;
                }

            }
            catch (Exception ex)
            {
                ret.IsSuccess = false;
                ret.Message = ex.Message;
            }

            return ret;
        }

        /// <summary>
        /// 上传双怠速
        /// </summary>
        /// <param name="strVin"></param>
        /// <param name="strJ"></param>
        /// <returns></returns>
        private ReturnInfo UploadSDSData(string strVin, string strJsonInfo)
        {
            ReturnInfo ret = new ReturnInfo();
            try
            {
                JObject json = JObject.Parse(strJsonInfo);

                string vehicleModel = GetJsonValue(json["vehicleData"]["vehicleModel"]);
                string vin = GetJsonValue(json["vehicleData"]["vin"]);
                string xxgkbh = GetJsonValue(json["vehicleData"]["xxgkbh"]);
                string reac = GetJsonValue(json["data"]["resultData"]["sdsData"]["reac"]);
                string lrco = GetJsonValue(json["data"]["resultData"]["sdsData"]["lrco"]);
                string llco = GetJsonValue(json["data"]["resultData"]["sdsData"]["llco"]);
                string lrhc = GetJsonValue(json["data"]["resultData"]["sdsData"]["lrhc"]);
                string llhc = GetJsonValue(json["data"]["resultData"]["sdsData"]["llhc"]);
                string hrco = GetJsonValue(json["data"]["resultData"]["sdsData"]["hrco"]);
                string hlco = GetJsonValue(json["data"]["resultData"]["sdsData"]["hlco"]);
                string hrhc = GetJsonValue(json["data"]["resultData"]["sdsData"]["hrhc"]);
                string hlhc = GetJsonValue(json["data"]["resultData"]["sdsData"]["hlhc"]);
                string leacmin = GetJsonValue(json["data"]["resultData"]["sdsData"]["leacmin"]);
                string leacmax = GetJsonValue(json["data"]["resultData"]["sdsData"]["leacmax"]);

                // 上传双怠速.
                string[] strPara = new string[] { vin, vehicleModel, xxgkbh, reac, lrco, llco, lrhc, llhc, hrco, hlco, hrhc, hrhc , leacmin , leacmax };
                ret = dataOperation.SaveENV_IDLESPEEDInfo(strPara);

                if (ret.IsSuccess == false)
                {
                    ret.Message = "上传双怠速错误:" + ret.Message;
                }

            }
            catch (Exception ex)
            {
                ret.IsSuccess = false;
                ret.Message = ex.Message;
            }

            return ret;
        }

        /// <summary>
        /// 上传加载减速
        /// </summary>
        /// <param name="strVin"></param>
        /// <param name="strJ"></param>
        /// <returns></returns>
        private ReturnInfo UploadLugdownData(string strVin, string strJsonInfo)
        {
            ReturnInfo ret = new ReturnInfo();
            try
            {
                JObject json = JObject.Parse(strJsonInfo);

                string vehicleModel = GetJsonValue(json["vehicleData"]["vehicleModel"]);
                string vin = GetJsonValue(json["vehicleData"]["vin"]);
                string xxgkbh = GetJsonValue(json["vehicleData"]["xxgkbh"]);
                string rateRevUp = GetJsonValue(json["data"]["resultData"]["lugdownData"]["rateRevUp"]);
                string rateRevDown = GetJsonValue(json["data"]["resultData"]["lugdownData"]["rateRevDown"]);
                string rev100 = GetJsonValue(json["data"]["resultData"]["lugdownData"]["rev100"]);
                string maxPower = GetJsonValue(json["data"]["resultData"]["lugdownData"]["maxPower"]);
                string maxPowerLimit = GetJsonValue(json["data"]["resultData"]["lugdownData"]["maxPowerLimit"]);
                string smoke100 = GetJsonValue(json["data"]["resultData"]["lugdownData"]["smoke100"]);
                string smoke80 = GetJsonValue(json["data"]["resultData"]["lugdownData"]["smoke80"]);
                string smokeLimit = GetJsonValue(json["data"]["resultData"]["lugdownData"]["smokeLimit"]);
                string nox = GetJsonValue(json["data"]["resultData"]["lugdownData"]["nox"]);
                string noxLimit = GetJsonValue(json["data"]["resultData"]["lugdownData"]["noxLimit"]);

                // 上传加载减速.
                string[] strPara = new string[] { vin, vehicleModel, xxgkbh, rateRevUp, rateRevDown, rev100, maxPower, maxPowerLimit, smoke100, smoke80, smokeLimit, nox, noxLimit };
                ret = dataOperation.SaveENV_METHODInfo(strPara);

                if (ret.IsSuccess == false)
                {
                    ret.Message = "上传双怠速错误:" + ret.Message;
                }

            }
            catch (Exception ex)
            {
                ret.IsSuccess = false;
                ret.Message = ex.Message;
            }

            return ret;
        }

        /// <summary>
        /// 上传稳态
        /// </summary>
        /// <param name="strVin"></param>
        /// <param name="strJ"></param>
        /// <returns></returns>
        private ReturnInfo UploadAsmData(string strVin, string strJsonInfo)
        {
            ReturnInfo ret = new ReturnInfo();
            try
            {
                JObject json = JObject.Parse(strJsonInfo);

                string vehicleModel = GetJsonValue(json["vehicleData"]["vehicleModel"]);
                string vin = GetJsonValue(json["vehicleData"]["vin"]);
                string xxgkbh = GetJsonValue(json["vehicleData"]["xxgkbh"]);
                string arhc5025 = GetJsonValue(json["data"]["resultData"]["asmData"]["arhc5025"]);
                string alhc5025 = GetJsonValue(json["data"]["resultData"]["asmData"]["alhc5025"]);
                string arco5025 = GetJsonValue(json["data"]["resultData"]["asmData"]["arco5025"]);
                string alco5025 = GetJsonValue(json["data"]["resultData"]["asmData"]["alco5025"]);
                string arnox5025 = GetJsonValue(json["data"]["resultData"]["asmData"]["arnox5025"]);
                string alnox5025 = GetJsonValue(json["data"]["resultData"]["asmData"]["alnox5025"]);
                string arhc2540 = GetJsonValue(json["data"]["resultData"]["asmData"]["arhc2540"]);
                string alhc2540 = GetJsonValue(json["data"]["resultData"]["asmData"]["alhc2540"]);
                string arco2540 = GetJsonValue(json["data"]["resultData"]["asmData"]["arco2540"]);
                string alco2540 = GetJsonValue(json["data"]["resultData"]["asmData"]["alco2540"]);
                string arnox2540 = GetJsonValue(json["data"]["resultData"]["asmData"]["arnox2540"]);
                string alnox2540 = GetJsonValue(json["data"]["resultData"]["asmData"]["alnox2540"]);

                // 上传稳态.
                string[] strPara = new string[] { vin, vehicleModel, xxgkbh, arhc5025, alhc5025, arco5025, alco5025, arnox5025, alnox5025, arhc2540, alhc2540, arco2540, alco2540 , arnox2540, alnox2540 };
                ret = dataOperation.SaveENV_STEADYSTATEInfo(strPara);

                if (ret.IsSuccess == false)
                {
                    ret.Message = "上传双怠速错误:" + ret.Message;
                }

            }
            catch (Exception ex)
            {
                ret.IsSuccess = false;
                ret.Message = ex.Message;
            }

            return ret;
        }
        #endregion

        /// <summary>
        /// 得到Json值
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        private string GetJsonValue(object obj)
        {
            string strRet = "";
            try
            {
                if(obj !=null)
                {
                    strRet = obj.ToString();
                }
                else
                {
                    strRet = "";
                }
            }
            catch(Exception ex)
            {
                strRet = "";
            }

            return strRet;
        }
    }
}
